package com.ojoin.trade.common.web.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.OfficeDao;
import com.ojoin.trade.common.web.domain.Office;

@Repository
public class OfficeDaoImpl extends BaseDaoImpl<Office> implements OfficeDao {
	
	public SqlSession getSqlSession() {
		return this.sqlSessionTemplate;
	}
	
	@Override
	public List<Office> findByParentIdsLike(Office entity) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		List list;
		try {
			  list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),entity);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		
		return list;
	}

	@Override
	public int updateParentIds(Office entity) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		int ef;
		try {
			ef = this.sqlSessionTemplate.update(getSqlName(mapMethodName),entity);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		return ef;
	}

	@Override
	public Office findByName(Office entity) {
		String mapMethodName = new Exception().getStackTrace()[0].getMethodName(); 
		Office one;
		try {
			  one = this.sqlSessionTemplate.selectOne(getSqlName(mapMethodName),entity);
		} catch (Exception e) {
			throw new DaoException(String.format("语句：%s",getSqlName(mapMethodName)), e);
		}
		
		return one;
	}

}
